<template>
  <div>
    <!-- 操作 -->
    <el-row class="setting-yly-row">
      <el-col :span="14" style="text-align:left;padding-left:15px" class="setting-yly-row-col">
        <el-input v-model="searchName" placeholder="请输入名称" size="small" style="max-width:240px" @keydown.enter="search">
          <el-button slot="suffix" type="text" size="small" class="search-button" @click="search">
            <i class="el-icon-search"></i>
          </el-button>
        </el-input>
      </el-col>
    </el-row>

    <!-- 表格 -->
    <div>
      <el-table :data="orderList" style="width:100%" stripe>
        <el-table-column prop="id" label="订单ID" align="center"></el-table-column>
        <el-table-column prop="name" label="商品名称" align="center"></el-table-column>
        <el-table-column prop="nickname" label="买家昵称" align="center"></el-table-column>
        <el-table-column prop="type" label="拼团类型" align="center"></el-table-column>
        <el-table-column prop="format_create_time" label="加入时间" align="center"></el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="scope" width="80px">
            <el-switch v-model="scope.row.status" active-color="#13ce66" active-value="1" inactive-value="0" @change="changeStatus(scope.row)"></el-switch>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div style="text-align:right;margin:15px 15px">
      <el-pagination class="page"
        background
        layout="total, prev, pager, next, jumper"
        :total="count"
        :page-size="10"
        :current-page="page"
        @size-change="changePage"
        @current-change="changePage">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getTuanOrderList } from '@/api/marketing'

export default {
  name: 'setting-yly',
  data() {
    return {
      page: 1,
      count: 1,

      orderList: [],

      searchName: '',
    }
  },
  mounted() {
    this.getTuanOrderList();

  },
  methods: {
    /**
     * 获取积分商品列表
     */
    getTuanOrderList() {
      const params = {
        key: this.$store.state.app.activeApp.saa_key,
        page: this.page,
        limit: 10
      };
      getTuanOrderList(params).then(res => {
        if(res.status === 200){
          this.orderList = res.data;
          this.count = parseInt(res.count);
        }else if(res.status === 204){
          this.orderList = [];
          this.count = 1;
        }else{
          this.$message.error(res.message);
        }
      })
    },
    /**
     * 翻页
     */
    changePage(page) {
      this.page = page;
      this.getTuanOrderList();
    },
    /**
     * 搜索
     */
    search() {
      const params = {
        key: this.$store.state.app.activeApp.saa_key,
        page: this.page,
        limit: 10,
        searchName: this.searchName
      };
      getTuanOrderList(params).then(res => {
        if(res.status === 200){
          this.orderList = res.data;
          this.count = parseInt(res.count);
        }else if(res.status === 204){
          this.orderList = [];
          this.count = 1;
        }else{
          this.$message.error(res.message);
        }
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.setting-yly-row{
  margin: 15px 0;
  text-align: center;
  height: 40px;
  line-height: 40px;
  &-col{
    padding: 0 15px;
    max-width: 95%;
    overflow: hidden;
    display: flex;
  }
}

</style>